package com.dgut.smart_house.exception;

import com.dgut.smart_house.enums.ResultCode;
import com.dgut.smart_house.util.RestResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public RestResult Handler(Exception e) {

        if (e instanceof MyException) {
            MyException myException = (MyException) e;
            return new RestResult(myException.getCode(),myException.getMessage(), null);
        } else {
            return new RestResult(ResultCode.FAIL, null);
        }

    }


}
